﻿using System.Drawing;

public class ImgCtrl
{
    public static void SaveImg(Image pic, string strPic)
    {
        pic.Save(strPic);
        //Bitmap currentBitmap = new Bitmap(strPic);
        //Graphics g = Graphics.FromImage(currentBitmap);

        //Process.Start(strPic);
    }

    /// <summary>
    /// 变成灰度图
    /// </summary>
    /// <param name="pic"></param>
    public static void ChangeHuidu(Bitmap pic)
    {
        Color currentColor;
        int r;

        Bitmap currentBitmap = (Bitmap)pic;
        Graphics g = Graphics.FromImage(currentBitmap);
        for (int w = 0; w < currentBitmap.Width; w++)
        {
            for (int h = 0; h < currentBitmap.Height; h++)
            {
                currentColor = currentBitmap.GetPixel(w, h);
                r = (currentColor.R + currentColor.G + currentColor.B) / 3;
                currentBitmap.SetPixel(w, h, Color.FromArgb(r, r, r));
            }
        }
        g.DrawImage(currentBitmap, 0, 0);
    }
}